<%--
  Created by IntelliJ IDEA.
  User: dzw
  Date: 2017/12/4
  Time: 13:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<style>
  #chanceA a{
    display: block;
    margin-top: 5px;
    color: #4FA5D0;
  }
</style>

<div class="row">
  <div class="col-lg-12">
    <div class="panel">
      <div class="panel-heading header">
        <h3 class="panel-title" id="title">合同评审登记表</h3>
      </div>

      <!-- BASIC FORM ELEMENTS -->
      <!--===================================================-->
      <form id="form_contractDeal_input" class="panel-body form-horizontal form-padding">
        <input type="hidden" name="keyId" id="keyId" value="${contractDeal.id}" />

        <div class="form-group">
          <label class="col-md-2 control-label">
            客户名称
            <i class="fa fa-asterisk txt-color-red"></i>
          </label>
          <div class="col-md-6">
            <input disabled type="text" id="customerInfo" class="form-control" placeholder="请输入客户名称" value="${contractDeal.customerInfo.name}">
            <input type="hidden" id="customerInfoId" name="customerInfoId" class="form-control" value="${contractDeal.customerInfo.id}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">合同名称<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="text" name="name" id="name" class="form-control" placeholder="请输入合同名称" value="${contractDeal.name}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">签约时间<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled placeholder="请选择签约时间" id="signDate" name="signDate" class="form-control" type="text" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${contractDeal.signDate}" />">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">合同金额<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input disabled type="number" name="contractMoney" id="contractMoney" class="form-control" placeholder="请输入合同金额" value="${contractDeal.contractMoney}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">是否存在业务机会<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <div class="radio">
              <input disabled type="radio" name="isHaveChance" id="isHaveChance1" value="是" class="magic-radio" <c:if test="${contractDeal.isHaveChance=='是'}"> checked</c:if> >
              <label for="isHaveChance1">是</label>
              <input disabled type="radio" name="isHaveChance" id="isHaveChance2" value="否" class="magic-radio" <c:if test="${contractDeal.isHaveChance=='否'}"> checked</c:if> >
              <label for="isHaveChance2">否</label>
            </div>
          </div>
        </div>

        <div class="form-group" id="chanceDiv" <c:if test="${contractDeal==null || contractDeal.isHaveChance=='否'}">style="display: none" </c:if> >
          <label class="col-md-2 control-label">
            关联业务机会
            <i class="fa fa-asterisk txt-color-red"></i>
          </label>
          <div class="col-md-6">
            <div id="chanceA">
              <c:if test="${contractDeal.businessChance!=null}">
                <a href="javascript:void(0)" onclick="toChance('${contractDeal.businessChance.id}')">${contractDeal.businessChance.name}</a>
              </c:if>
            </div>
            <input type="hidden" id="businessChanceId" name="businessChanceId" class="form-control" value="${contractDeal.businessChance.id}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">提交人</label>
          <div class="col-md-2">
            <p class="form-control-static">${contractDeal.creater.name}</p>
          </div>
          <label class="col-md-2 control-label">提交日期</label>
          <div class="col-md-2">
            <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${contractDeal.createTime}" /></p>
          </div>
        </div>

        <c:if test='${contractDeal.processState != "Finished" && contractDeal.processState != "Deny"}'>

          <div class="form-group">
            <label class="col-md-2 control-label">
              是否抄送
            </label>
            <div class="col-md-6">
              <div class="radio">
                <input type="radio" id="remindYes" name="remind" value="1" class="magic-radio">
                <label for="remindYes">是</label>
                <input type="radio" id="remindNo" name="remind" value="0" class="magic-radio">
                <label for="remindNo">否</label>
              </div>
            </div>
          </div>

          <div class="form-group" style="display: none" id="showRemind">
            <label class="col-md-2 control-label">
              <a href="javascript:void(0);" onclick="fn_members_dialog_select('remindUser', 'remindUserId')" style="color: #4FA5D0">抄送人员</a>
              <i class="fa fa-asterisk txt-color-red"></i>
            </label>
            <div class="col-md-6">
              <input type="text" id="remindUser" name="remindUser" class="form-control" placeholder="请选择抄送人员" readonly value="" onclick="fn_members_dialog_select('remindUser', 'remindUserId')">
              <input type="hidden" id="remindUserId" name="remindUserId" value="">
            </div>
          </div>

          <div class="form-group">
            <label class="col-md-2 control-label">
              下一步流程
            </label>
            <div class="col-md-6">
              <div class="radio">
                <input type="radio" id="nextNo" name="next" value="0" class="magic-radio">
                <label for="nextNo">归档</label>
                <input type="radio" id="nextYes" name="next" value="1" class="magic-radio">
                <label for="nextYes">选择下一步操作人</label>
              </div>
            </div>
          </div>

          <div class="form-group" style="display:none" id="showNextStep">
            <label class="col-md-2 control-label">
              <a href="javascript:void(0);" onclick="fn_member_dialog_select('editors', 'editorsId')" style="color: #4FA5D0">选择下一步操作人</a>
              <i class="fa fa-asterisk txt-color-red"></i>
            </label>
            <div class="col-md-6">
              <input type="text" id="editors" name="editors" class="form-control" placeholder="请选择下一步操作人" readonly onclick="fn_member_dialog_select('editors', 'editorsId')" >
              <input type="hidden" id="editorsId" name="editorsId">
            </div>
          </div>
        </c:if>



      </form>
      <!--===================================================-->
      <!-- END BASIC FORM ELEMENTS -->

    </div>
  </div>

  <jsp:include page="common.jsp"/>
</div>

<script>
  var state = "${contractDeal.processState}";
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";
  var stepNo = "${stepNo}";

  $(function(){
    loadURL("<%=path%>/com/running/newWorkflow?bussinessId="+$("#form_contractDeal_input #keyId").val()+"&type=flow",$('#showFlow'));
    loadURL("<%=path%>/com/running/newWorkflow?bussinessId="+$("#form_contractDeal_input #keyId").val()+"&type=next",$('#showNext'));
    if(state !=  "Finished" &&  state !=  "Deny"){
      __ajax_post("<%=path%>/com/running/newOperateType",{keyId: $("#form_contractDeal_input #keyId").val()},function(pdata){
        var area = $("div.flow .panel-footer");
        $(pdata.datarows).each(function(i,v){
          var str = '<a id="left_foot_btn_'+ v.action+'" class="btn btn-warning" href="javascript:void(0);"><i class="fa fa-upload">'+ v.name+'</i></a>&nbsp;';

          $(area).append(str);
        });
        //通过
        $("#left_foot_btn_approve").off("click").on("click",function(){
          if($(":checked[name='next']").length < 1){
            __toastr_warning("请选择下一步流程");
            return false;
          }else if($(":checked[name='next']").val()==1 && $("#editorsId").val()==""){
            __toastr_warning("请选择下一步审批人");
            return false;
          }
          __form_approve("form_contractDeal_input ","<%=path%>/com/contractDeal/approve" );
        });
        //退回
        $("#left_foot_btn_sendback").off("click").on("click",function(){
          var vActionUrl="<%=path%>/com/contractDeal/back";
          var keyId = $("input#keyId").val();
          var aData={keyId:$("input#keyId").val()};
          __form_back(keyId, vActionUrl, aData);

        });
        //否决
        $("#left_foot_btn_deny").off("click").on("click",function(){
          var vActionUrl="<%=path%>/com/contractDeal/deny";
          var keyId = $("input#keyId").val();
          var aData={keyId:$("input#keyId").val()};
          __form_deny(keyId, vActionUrl, aData);
        });
      });
    }

    //流程信息展开
    $('#flow,#next').click(function(){
      if($(this).hasClass("right")){
        $(this).removeClass("right").addClass("down");
        $(this).parent(".f_title").next("div.f_content").show();
      }else{
        $(this).removeClass("down").addClass("right");
        $(this).parent(".f_title").next("div.f_content").hide();
      }
    });

  });

  //下一步点击
  $(':radio[name="next"]').click(function(){
    if($(this).val() == "1"){
      $('#showNextStep').show();
    }else{
      $('#showNextStep').hide();
    }
  });

  //抄送点击
  $(':radio[name="remind"]').click(function(){
    if($(this).val() == "1"){
      $('#showRemind').show();
    }else{
      $('#showRemind').hide();
    }
  });

  function toChance(id){
    __open_dialog_form_read('机会登记','<%=path%>/com/businessChance/read?keyId='+id);
  }

  //编辑
  $("a[key='ajax_edit3']").unbind("click").bind("click",function(){
    loadURL("<%=path%>/com/contractDeal/input?keyId="+$("#keyId").val()+"&draft="+draft+"&todo="+todo+"&remind="+remind+"&record="+record+"&index="+index,$('#page-content'));
  });

  ///返回视图
  $("#apply-re-common").click(function(){
    if(index==1){
      loadURL("menu/dashboard",$('#page-content'));
    }else if(todo==1){
      loadURL("menu/toDo",$('#page-content'));
    }else if(remind==1){
      loadURL("menu/remind",$('#page-content'));
    }else if(record==1){
      loadURL("menu/taskRecord?type=1",$('#page-content'));
    }else if(record==2){
      loadURL("menu/taskRecord?type=2",$('#page-content'));
    }else if(draft==1){
      loadURL("menu/draft",$('#page-content'));
    }else{
      returnToHashUrl()
    }
  });

</script>




